Ensure all natives request at least a 1px wide surface
authorBenjamin Otte <otte@redhat.com>
Sat, 22 Feb 2020 03:49:52 +0000 (04:49 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 22 Feb 2020 04:50:07 +0000 (05:50 +0100)
FIXME: Is this necessary?

Could the surfaces just clamp to 1x1 themselves?
We recently declared that surfaces can decide on whatever size they want
so natives need to inspect the size they requested anyway.

gtk/gtkdragicon.c
gtk/gtkpopover.c
gtk/gtktooltipwindow.c
gtk/gtkwindow.c

index 2e33f1c66c9a73f9c8aa59a23e6e5c8be0201762..e0b957bf569a206d1341bc58ba41ecbb05395f2a 100644 (file)
@@ -129,7 +129,9 @@ gtk_drag_icon_move_resize (GtkDragIcon *icon)
   if (icon->surface)
     {
       gtk_widget_get_preferred_size (GTK_WIDGET (icon), NULL, &req);
-      gdk_surface_resize (icon->surface, req.width, req.height);
+      gdk_surface_resize (icon->surface,
+                          MAX (1, req.width),
+                          MAX (1, req.height));
     }
 }
 
@@ -256,8 +258,6 @@ gtk_drag_icon_size_allocate (GtkWidget *widget,
 {
   GtkDragIcon *icon = GTK_DRAG_ICON (widget);
 
-  gtk_drag_icon_move_resize (icon);
-
   if (icon->widget)
     gtk_widget_allocate (icon->widget, width, height, baseline, NULL);
 }
index 7c202414ee7194bb610232017df0b9918e3371c5..286388bb2d8d9a6503dbd588cdb3809b509eb7f4 100644 (file)
@@ -546,7 +546,8 @@ present_popup (GtkPopover *popover)
   layout = create_popup_layout (popover);
   gtk_widget_get_preferred_size (GTK_WIDGET (popover), NULL, &req);
   if (gdk_surface_present_popup (priv->surface,
-                                 req.width, req.height,
+                                 MAX (req.width, 1),
+                                 MAX (req.height, 1),
                                  layout))
     update_popover_layout (popover, layout);
 }
index 4af7fc613d4df02c410de76c2a732a5b9c6a00e7..bd95379fb07486f7be12ebff0b3aed1499660c10 100644 (file)
@@ -125,35 +125,24 @@ create_popup_layout (GtkTooltipWindow *window)
 }
 
 static void
-relayout_popup (GtkTooltipWindow *window)
+gtk_tooltip_window_relayout (GtkTooltipWindow *window)
 {
+  GtkRequisition req;
   GdkPopupLayout *layout;
 
-  if (!gtk_widget_get_visible (GTK_WIDGET (window)))
+  if (!gtk_widget_get_visible (GTK_WIDGET (window)) ||
+      window->surface == NULL)
     return;
 
+  gtk_widget_get_preferred_size (GTK_WIDGET (window), NULL, &req);
   layout = create_popup_layout (window);
   gdk_surface_present_popup (window->surface,
-                             gdk_surface_get_width (window->surface),
-                             gdk_surface_get_height (window->surface),
+                             MAX (req.width, 1),
+                             MAX (req.height, 1),
                              layout);
   gdk_popup_layout_unref (layout);
 }
 
-static void
-gtk_tooltip_window_move_resize (GtkTooltipWindow *window)
-{
-  GtkRequisition req;
-
-  if (window->surface)
-    {
-      gtk_widget_get_preferred_size (GTK_WIDGET (window), NULL, &req);
-      gdk_surface_resize (window->surface, req.width, req.height);
-
-      relayout_popup (window);
-    }
-}
-
 static void
 gtk_tooltip_window_native_check_resize (GtkNative *native)
 {
@@ -164,7 +153,7 @@ gtk_tooltip_window_native_check_resize (GtkNative *native)
     gtk_widget_ensure_allocate (widget);
   else if (gtk_widget_get_visible (widget))
     {
-      gtk_tooltip_window_move_resize (window);
+      gtk_tooltip_window_relayout (window);
       if (window->surface)
         gtk_widget_allocate (GTK_WIDGET (window),
                              gdk_surface_get_width (window->surface),
@@ -281,7 +270,7 @@ surface_transform_changed_cb (GtkWidget               *widget,
 {
   GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
 
-  relayout_popup (window);
+  gtk_tooltip_window_relayout (window);
 
   return G_SOURCE_CONTINUE;
 }
@@ -361,8 +350,6 @@ gtk_tooltip_window_size_allocate (GtkWidget *widget,
   GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
   GtkWidget *child;
 
-  gtk_tooltip_window_move_resize (window);
-
   child = gtk_bin_get_child (GTK_BIN (window));
 
   if (child)
@@ -608,6 +595,6 @@ gtk_tooltip_window_position (GtkTooltipWindow *window,
   window->dx = dx;
   window->dy = dy;
 
-  relayout_popup (window);
+  gtk_tooltip_window_relayout (window);
 }
 
index 7b1c9c2f6dac2c7866599b1cb39de0c74f1bbb43..c62fa14567d3314cf269355d15617919e6a28db1 100644 (file)
@@ -5484,8 +5484,8 @@ gtk_window_realize (GtkWidget *widget)
   gtk_widget_get_allocation (widget, &allocation);
 
   surface = gdk_surface_new_toplevel (gtk_widget_get_display (widget),
-                                      allocation.width,
-                                      allocation.height);
+                                      MAX (1, allocation.width),
+                                      MAX (1, allocation.height));
   priv->surface = surface;
   gdk_surface_set_widget (surface, widget);